package sil;

import java.util.Map;

import clojure.lang.RT;
import container.ProbabilityContainer;
import container.ProbabilityParameters;

/**
 * Contains methods for calculations of probabilities for the silhouette system.
 * 
 * @author Marcus Lindner
 * @author Joana Otetelisanu
 * 
 */
public enum SilhouetteProbabilityCalculation {
    ;

    /**
     * Returns a {@link ProbabilityContainer} which contains the probability to
     * get the amount of
     * damage boxes and the probabilities to achieve specified MoS values.
     * 
     * @param parameters conditions for the calculation of the probabilities
     * @return a {@link ProbabilityContainer}
     */
    @SuppressWarnings("unchecked") // Clojure ensures the correct return map type
    public static final ProbabilityContainer calculateFullProbabilitySet(
	    ProbabilityParameters parameters) {
	Map<Integer, Number> mosProbability = null;
	Map<Integer, Number> damageProbability = null;
	Integer expectedMoSValue = null;
	Integer expectedDamageValue = null;
	
	try {   
	    mosProbability = (Map<Integer, Number>) RT.var("clj.silprob", "getMoSMap").invoke(parameters);
	    
	    damageProbability = (Map<Integer, Number>) RT.var("clj.silprob", "getDamageProbability").invoke(
		    					Integer.valueOf(parameters.getDamageMultiplicator()),
		    					Integer.valueOf(parameters.getTargetArmor()),
		    					mosProbability);
	    
	    expectedMoSValue = (Integer) RT.var("clj.silprob", "expectedValue").invoke(mosProbability);
	    expectedDamageValue = (Integer) RT.var("clj.silprob", "expectedValue").invoke(damageProbability);
	    
	} catch (Exception e) {
	    e.printStackTrace();
	}

	final ProbabilityContainer container = new ProbabilityContainer();
	container.setDamageProbabilities(damageProbability);
	container.setMosProbabilities(mosProbability);
	container.setMosExpectedValue(expectedMoSValue);
	container.setDamageExpectedValue(expectedDamageValue);
	
	return container;
    }
}
